package main

import (
	"bufio"
	"flag"
	"fmt"
	"os"

	"golang.org/x/text/encoding/simplifiedchinese"
)

func main() {
	f := flag.String("f", "", "file path")
	flag.Parse()
	if *f == "" {
		fmt.Println("use f to set file path")
		return
	}
	file, err := os.Open(*f)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer file.Close()

	reader := bufio.NewReader(file)
	var (
		line    []byte
		readerr error
	)
	for readerr == nil {
		if line, _, readerr = reader.ReadLine(); readerr != nil {
			continue
		}
		if line, readerr = simplifiedchinese.GBK.NewDecoder().Bytes(line); readerr != nil {
			continue
		}
		fmt.Println(string(line))
	}
}
